package Day04;

public class Day04isPalindrome {
    public static void main(String[] args) {
        System.out.println(isPalindrome(121));
        System.out.println(isPalindrome(12322321));
        System.out.println(isPalindrome(10));
    }
    public static boolean isPalindrome(int x) {
        String s = String.valueOf(x);
        char[] c = s.toCharArray();
        int n = c.length;
        int flag = n%2==0? 2:1;
        int mid = n/2;
        int left = mid-flag;
        int right = mid+1;
        if(flag==2&&c[mid-1]!=c[mid]){
            return false;
        }
        while (left>=0&&right<n){
            if(c[left]!=c[right]){
                return false;
            }
            left--;
            right++;

        }
        return true;
    }
    public static boolean isPalindrome2(int x){
        if(x<0) return false;
        String s = String.valueOf(x);
        for (int i = 0;i<s.length()/2;i++){
            if (s.charAt(i)!=s.charAt(s.length()-1-i)){
                return false;
            }
        }
        return true;
    }
}
